﻿using System;
using System.ComponentModel;
using SedionFormDesigner.Service;

namespace SedionFormDesigner.Infrastructure
{
    internal class SelectionItem
    {
        // 被选中的组件
        private Component component;
        private SedionSelectionService selectionMng;
        // 是否为主选择对象
        private Boolean primary;

        internal event EventHandler SelectionItemInvalidate;
        internal event EventHandler SelectionItemDispose;

        internal SelectionItem(SedionSelectionService selectionMng, Component component)
        {
            this.component = component;
            this.selectionMng = selectionMng;
        }

        internal Component Component
        {
            get
            {
                return component;
            }
        }

        /// <summary>
        ///  确定是否为主要的那个组件,因为那个有着不同的句柄
        /// </summary>
        internal virtual Boolean Primary
        {
            get
            {
                return primary;
            }
            set
            {
                if (this.primary != value)
                {
                    this.primary = value;
                    if (SelectionItemInvalidate != null)
                    {
                        SelectionItemInvalidate(this, EventArgs.Empty);
                    }
                }
            }
        }

        internal virtual void Dispose()
        {
            if (primary)
                selectionMng.SetPrimarySelection((SelectionItem)null);
            if (SelectionItemDispose != null)
                SelectionItemDispose(this, EventArgs.Empty);
        }
    }
}
